Aims.We describe a deep and wide search for optical GRB afterglows in images taken with MegaCAM at the Canada France Hawaii Telescope, within the framework of the CFHT Legacy Survey. Methods.This search is performed in near real-time thanks to a Real Time Analysis System (RTAS) called “Optically Selected GRB Afterglows”, which has been installed on a dedicated computer in Hawaii. This pipeline automatically and quickly analyzes Megacam images to construct catalogs of astronomical objects, and compares catalogs made from images taken at different epochs to produce a list of astrometrically and photometrically variable objects. These objects are then displayed on a web page to be characterized by a member of the collaboration. ...